home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 9485 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: [Q] Template instantiation
  5. Date: 2 Mar 1996 00:16:32 GMT
  6. Organization: Borland International
  7. Message-ID: <4h8411$q8k@druid.borland.com>
  8. References: <37116784wnr@parkbayl.demon.co.uk>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <37116784wnr@parkbayl.demon.co.uk>, martin@parkbayl.demon.co.uk 
  15. says...
  16. >
  17. >Can anyone tell me if its possible to instantiate a template with a class 
  18. >that is in itself a template.
  19. >
  20. >i.e. I have two classes
  21. >
  22. >template <class T>
  23. >class Node
  24. >{
  25. >        .. omitted..
  26. >private:
  27. >        T* nodeObject;
  28. >};
  29. >
  30. >template <class X>
  31. >class Queue
  32. >{
  33. >        ... omitted ...
  34. >private:
  35. >        X* queueObject;
  36. >};
  37. >
  38. >Queue<Node<int>> myQueue;               // Crazy as it may seem 
  39. >                                // this doesn't work
  40. >
  41. >i.e. I want to instantiate a Queue object which holds pointers to Node 
  42. >objects which hold pointers to ints.
  43. >
  44. >Am I on another planet??!
  45.  
  46. Nope, just not playing compiler properly. Being human, you read that 
  47. declaration as involving two templates. The compiler, not being human, read it 
  48. literally, saw a >> operator, and concluded that nothing after that point made 
  49. any sense. Unfortunately, the compiler is right. Put a space between the two 
  50. >s and the compiler will read it the same way you do.
  51.     -- Pete
  52.  
  53.